%!  TEX Format     = LaTeX2e
%!  TEX TS-program = XeLaTeX
%!  TEX encoding   = utf-8

%!  Copyright 2023 Liqing Elaina Shi（石礼晴）
%!  Document under the terms of the Creative Commons
%!  Attribution 4.0 International (CC BY 4.0)
%!  http://creativecommons.org/licenses/by/4.0/
%!  Permission is granted to copy, distribute and/or modify this

%!  The class file for my own articles and books (for chinese and english).

%!  Magicat, means magic cat (so cute isn't it), she is my magic pat.
%!  Of cause, she is a "cyber pat" :D


%!  Magicat              / 魔法猫猫
%!  Liqing Elaina Shi    / 石礼晴
%!  version              / 1.6-classic

%   Basic settings for the documentclass
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{magicat-classic}[2023/04/13 Nya!]

%   Some basic commands
\newcommand{\cmd}{\newcommand}
\cmd{\rcmd}{\renewcommand}
\cmd{\pcmd}{\providecommand}
\cmd{\pack}{\RequirePackage}
\cmd{\packoption}{\PassOptionsToPackage}

%   Introduce key-val setting
%!  These setting are used to define the boolean/string options for documentclass.
%!  We use string options to reserve interfaces for future updates.
\pack{kvoptions}
\pack{etoolbox}

%   Family and prefix name of the documentclass
\SetupKeyvalOptions{
    family=@cat,
    prefix=@cat@,
    setkeys=\kvsetkeys
}

%!  You can use \kv to add backwards compatibilitiy of options, e.g. \DeclareVoidOption.  
\cmd{\ckv}[1]{\kvsetkeys{@cat}{#1}}

%   Options

%   Papersize setting                   (default: a4)
\DeclareStringOption[a4]{size}
%!  a4: a4paper, 75% scale.
%!  b5: b5paper, 75% scale.

%   Indent-first setting                (default: true)
\DeclareBoolOption[true]{indent}
%!  true: first indent 2ex.
%!  false: non first indent.

%   Language                            (default: zhcn)
\DeclareStringOption[zhcn]{lang}
%!  zhcn: 简体中文
%!  en: English
%!  fr: Français

%   Color                               (default: default)
\DeclareStringOption[default]{color}
%!  default: default color scheme.
%!  none: no color scheme.

%   Chapter or section                  (default: section)
\DeclareStringOption[section]{title}
%!  section: section.
%!  chapter: chapter.

%   Mode                                (default: math)
\DeclareStringOption[math]{mode}
%!  math: math mode.
%!  text: text mode.

%   Backwards compatibility
%   \DeclareVoidOption{a4}{\ckv{size=a4}}
%   \DeclareVoidOption{b5}{\ckv{size=b5}}

%   \DeclareVoidOption{zhcn}{\ckv{lang=zhcn}}
%   \DeclareVoidOption{en}{\ckv{lang=en}}
%   \DeclareVoidOption{fr}{\ckv{lang=fr}}

%   \DeclareVoidOption{default}{\ckv{color=default}}
%   \DeclareVoidOption{none}{\ckv{color=none}}

%   \DeclareVoidOption{section}{\ckv{title=section}}
%   \DeclareVoidOption{chapter}{\ckv{title=chapter}}

%   \DeclareVoidOption{math}{\ckv{mode=math}}
%   \DeclareVoidOption{text}{\ckv{mode=text}}

%   Provide the key-val options can be passed
\ProcessKeyvalOptions*
\relax




%!  Part I: Basic setting
%!  We used some basic packages and made some settings based on them in this part.

%   Induce basic documentclass
%!  Our work is based on article.cls.
\LoadClass[18pt]{article}

%   String input and handle
\pack{xstring}

%   Text-indent
\pack{indentfirst}                                          
\if@cat@indent
    \setlength{\parindent}{2em}
\else
    \relax
\fi

%   Papersize setting
\pack{geometry}
\IfStrEq{\@cat@size}{a4}{}{\geometry{a4paper, scale=0.75}}
\IfStrEq{\@cat@size}{b5}{}{\geometry{b5paper, scale=0.75}}


%   Use xeCJK to input Chinese
%!  We do not use ctex because it will invalidate key-val options.
\pack{fontspec}
\pack[CJKchecksingle]{xeCJK}
\pack{CJKnumb}

%!  You can introduce several fonts here.
%!  Otherwise you need at least Fandol as default font.

%   Code input support for outputting code style boxes
\pack{listings}
%   Setting of listings box
\lstset{
    basicstyle=\tt,
    numbers=left,
    numbersep=2em,
    numberstyle=\footnotesize,
    frame=shadowbox,
    rulesepcolor=\color{red!20!green!20!blue!20},
    keywordstyle=\color{blue},
    stringstyle=\color{purple},
    commentstyle=\color{green!35!black}
}

%   Chapter or section
\pack{titlesec}
\pack{titletoc}
\ifdefstring{\@cat@title}{chapter}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \titleformat{\section}[block]{\Large\bfseries}{第\CJKnumber{\arabic{section}}章}{1em}{}[]
        \titlecontents{section}[0pt]{\addvspace{1.5pt}\filright\bf}{\contentspush{第\CJKnumber{\thecontentslabel}章\quad}}{}{\titlerule*[8pt]{.}\contentspage}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \titleformat{\section}[block]{\Large\bfseries}{Chapter \arabic{section}}{1em}{}[]
            \titlecontents{section}[0pt]{\addvspace{1.5pt}\filright\bf}{\contentspush{Chapter \thecontentslabel\quad}}{}{\titlerule*[8pt]{.}\contentspage}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \titleformat{\section}[block]{\Large\bfseries}{Chapitre \arabic{section}}{1em}{}[]
                \titlecontents{section}[0pt]{\addvspace{1.5pt}\filright\bf}{\contentspush{Chapitre \thecontentslabel\quad}}{}{\titlerule*[8pt]{.}\contentspage}
            }{
                \relax
            }
        }
    }
}{
    \relax
}

%   Some color packages
\pack[svgnames,dvipsnames]{xcolor}
\pack{colortbl}

%   Mathematics packages
\pack{amsmath}
\pack{amssymb}                                                                %!  Provide necessary math related content.
\pack{amsthm}                                                                 %!  Provide proof environment, and other environments are left to be defined by the theorems package.
\pack{amsfonts}                                                               %!  Provide necessary math related fonts.
\pack{mathtools}                                                              %!  Provide some mathematical commands.
\pack{relsize}                                                                %!  Provide multi-size for operators, e.g. \mathsmall/large is provided by this package, and is unnecessary but we sometimes need it.
\pack{bbm}                                                                    %!  Provide another \mathbb font for beautify.
\pack[bbgreekl]{mathbbol}                                                     %!  Provide another \mathbb font for custom symbols.
\pack{mathrsfs}                                                               %!  Provide classic \mathscr font.
\pack[mathscr]{eucal}                                                         %!  Provide another \mathscr font for beautify.
\pack{stmaryrd}                                                               %!  Provide some special mathematical symbols, such as empty square brackets \llbracket, \rrbacket.
\pack{array}                                                                  %!  Provide some arrows.
\pack[new]{old-arrows}                                                        %!  Provide some special arrows, e.g. \longhookrightarrow.
\pack{tikz}                                                                   %!  Provide drawing functions.
\usetikzlibrary{arrows, backgrounds, calc, cd, matrix, patterns, positioning}           %!  Provide other functions for tikz.
\pack{forest}                                                                 %!  Provide tikz-based tree drawing.

%   beautify packages
\pack{bbding}                                                                 %!  Provide some special symbols, e.g. hexagram (or star for David) \DavidStar.
\pack{halloweenmath}                                                          %!  Provide special symbols related to Halloween and witch, I used it because I am a witch.
\pack{niceframe}                                                              %!  Provide some beautiful frame.
\pack{ulem}                                                                   %!  Provide equal-height underline to beautify the built-in  underline and other commands.
\pack{tcolorbox}                                                              %!  Provide color box drawing.
\tcbuselibrary{most, skins, breakable, theorems}                                        %!  Provide other functions for tcolorbox.
\pack[iso, english]{isodate}                                                  %!  Provide another version of \today.

%   Functional packages
\pack[unicode, bookmarksnumbered]{hyperref}                                   %!  Provide hyperreference.                                
\pack{multicol}                                                               %!  Provide column splitting function for emergency.
\pack{graphicx}                                                               %!  Provide insert picture function.  
\pack{tabularx}                                                               %!  Provide insert Table function.
\pack{pdfpages}                                                               %!  Provide insert .pdf function for emergency.

%   Fix \emph command
\AtBeginDocument{\normalem}

%   Hyperreference settings
\ifdefstring{\@cat@color}{default}{
    \hypersetup{
        colorlinks=true,
        citecolor=red,
        linkcolor=black,
        urlcolor=blue
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \hypersetup{
            colorlinks=true,
            citecolor=black,
            linkcolor=black,
            urlcolor=gray
        }
    }{
        \relax
    }
}




%!  Part II: Environments
%!  We have defined many environments, and different effects can be obtained according to different options.

%   Table of contents
\ifdefstring{\@cat@lang}{zhcn}{
    \rcmd{\contentsname}{目录}
}{
    \ifdefstring{\@cat@lang}{en}{
        \rcmd{\contentsname}{Contents}
    }{
        \ifdefstring{\@cat@lang}{fr}{
            \rcmd{\contentsname}{Catalogue}
        }{
            \relax
        }
    }
}

%   Figure and table
\ifdefstring{\@cat@lang}{zhcn}{
    \rcmd{\figurename}{图}
    \rcmd{\tablename}{表}
}{
    \ifdefstring{\@cat@lang}{en}{
        \rcmd{\figurename}{Figure}
        \rcmd{\tablename}{Table}
    }{
        \ifdefstring{\@cat@lang}{fr}{
            \rcmd{\figurename}{Figure}
            \rcmd{\tablename}{Tableau}
        }{
            \relax
        }
    }
}

%   References
\ifdefstring{\@cat@lang}{zhcn}{
    \rcmd{\refname}{参考文献}
}{
    \ifdefstring{\@cat@lang}{en}{
        \rcmd{\refname}{{References}}
    }{
        \ifdefstring{\@cat@lang}{fr}{
            \rcmd{\refname}{Références}
        }{
            \relax
        }
    }
}

%   Appendix
\pack[title]{appendix}
\ifdefstring{\@cat@lang}{zhcn}{
    \rcmd{\appendixtocname}{附录}
    \rcmd{\appendixname}{附录}
}{
    \ifdefstring{\@cat@lang}{en}{
        \rcmd{\appendixtocname}{Appendix}
        \rcmd{\appendixname}{Appendix}
    }{
        \ifdefstring{\@cat@lang}{fr}{
            \rcmd{\appendixtocname}{Annexe}
            \rcmd{\appendixname}{Annexe}
        }{
            \relax
        }
    }
}

%   Restruction of \begin ... \end
\cmd{\env}[2]{\begin{#1}#2\end{#1}}

%   Definition
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{definition}{\textbf{定义}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{definition}{\textbf{Definition}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{definition}{\textbf{Définition}}{%
                    colback=red!5,
                    colframe=red!75!black,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{definition}{定义}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{definition}{Definition}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{definition}{Définition}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Definition-Construction
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{definition-construction}{\textbf{定义-构造}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{definition-construction}{\textbf{Definition-Construction}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{definition-construction}{\textbf{Définition-Construction}}{%
                    colback=red!5,
                    colframe=red!75!black,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{definition-construction}{定义}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{definition-construction}{Definition}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{definition-construction}{Définition}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Definition-Proposition
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{definition-proposition}{\textbf{定义-命题}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{definition-proposition}{\textbf{Definition-Proposition}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{definition-proposition}{\textbf{Définition-Proposition}}{%
                    colback=red!5,
                    colframe=red!75!black,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{definition-proposition}{定义-命题}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{definition-proposition}{Definition-Proposition}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{definition-proposition}{Définition-Proposition}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Definition-Lemma
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{definition-lemma}{\textbf{定义-引理}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{definition-lemma}{\textbf{Definition-Lemma}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{definition-lemma}{\textbf{Définition-Lemme}}{%
                    colback=red!5,
                    colframe=red!75!black,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{definition-lemma}{定义-引理}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{definition-lemma}{Definition-Lemma}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{definition-lemma}{Définition-Lemme}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Definition-Theorem
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{definition-theorem}{\textbf{定义-定理}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{definition-theorem}{\textbf{Definition-Theorem}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{definition-theorem}{\textbf{Définition-Théorème}}{%
                    colback=red!5,
                    colframe=red!75!black,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{definition-theorem}{定义-定理}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{definition-theorem}{Definition-Theorem}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{definition-theorem}{Définition-Théorème}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Definition-Axiom
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{definition-axiom}{\textbf{定义-公理}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{definition-axiom}{\textbf{Definition-Axiom}}{%
                colback=red!5,
                colframe=red!75!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{definition-axiom}{\textbf{Définition-Axiôme}}{%
                    colback=red!5,
                    colframe=red!75!black,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{definition-axiom}{定义-公理}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{definition-axiom}{Definition-Axiom}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{definition-axiom}{Définition-Axiôme}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Construction
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{construction}{\textbf{构造}}{%
            colback=SpringGreen!10,
            colframe=SeaGreen!75!PineGreen,
            boxrule=1pt,
            toptitle=1mm,
            bottomtitle=1mm,
            left=8pt,
            right=8pt,
            arc=0mm,
            opacityback=0.5,
            separator sign={.},
            breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{construction}{\textbf{Construction}}{%
                colback=SpringGreen!10,
                colframe=SeaGreen!75!PineGreen,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{construction}{\textbf{Construction}}{%
                    colback=SpringGreen!10,
                    colframe=SeaGreen!75!PineGreen,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{construction}{构造}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{construction}{Construction}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{construction}{Construction}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Conjecture
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{conjecture}{\textbf{猜想}}{%
            colback=Melon!10,
            colframe=Peach!75!Orange,
            boxrule=1pt,
            toptitle=1mm,
            bottomtitle=1mm,
            left=8pt,
            right=8pt,
            arc=0mm,
            opacityback=0.5,
            separator sign={.},
            breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{conjecture}{\textbf{Conjecture}}{%
                colback=Melon!10,
                colframe=Peach!75!Orange,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{conjecture}{\textbf{Conjecture}}{%
                    colback=Melon!10,
                    colframe=Peach!75!Orange,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{conjecture}{猜想}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{conjecture}{Conjecture}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{conjecture}{Conjecture}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Proposition
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{proposition}{\textbf{命题}}{%
            colback=pink!20,
            colframe=CarnationPink,
            boxrule=1pt,
            toptitle=1mm,
            bottomtitle=1mm,
            left=8pt,
            right=8pt,
            arc=0mm,
            opacityback=0.5,
            separator sign={.},
            breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{proposition}{\textbf{Proposition}}{%
            colback=pink!20,
            colframe=CarnationPink,
            boxrule=1pt,
            toptitle=1mm,
            bottomtitle=1mm,
            left=8pt,
            right=8pt,
            arc=0mm,
            opacityback=0.5,
            separator sign={.},
            breakable
        }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{proposition}{\textbf{Proposition}}{%
                    colback=pink!20,
                    colframe=CarnationPink,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{proposition}{命题}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{proposition}{Proposition}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{proposition}{Proposition}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Lemma
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{lemma}{\textbf{引理}}{%
            colback=LightSlateBlue!30,
            colframe=LightSlateBlue!70,
            boxrule=1pt,
            toptitle=1mm,
            bottomtitle=1mm,
            left=8pt,
            right=8pt,
            arc=0mm,
            opacityback=0.5,
            separator sign={.},
            breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{lemma}{\textbf{Lemma}}{%
                colback=LightSlateBlue!30,
                colframe=LightSlateBlue!70,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{lemma}{\textbf{Lemme}}{%
                    colback=LightSlateBlue!30,
                    colframe=LightSlateBlue!70,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{lemma}{引理}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{lemma}{Lemma}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{lemma}{Lemme}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Theorem
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{theorem}{\textbf{定理}}{%
            colback=SeaGreen!10!CornflowerBlue!10,
            colframe=RoyalPurple!55!Aquamarine!100!,
            boxrule=1pt,
            toptitle=1mm,
            bottomtitle=1mm,
            left=8pt,
            right=8pt,
            arc=0mm,
            opacityback=0.5,
            separator sign={.},
            breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{theorem}{\textbf{Theorem}}{%
                colback=SeaGreen!10!CornflowerBlue!10,
                colframe=RoyalPurple!55!Aquamarine!100!,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{theorem}{\textbf{Théorème}}{%
                    colback=SeaGreen!10!CornflowerBlue!10,
                    colframe=RoyalPurple!55!Aquamarine!100!,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{theorem}{定理}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{theorem}{Theorem}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{theorem}{Théorème}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Axiom
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{axiom}{\textbf{公理}}{%
            colback=LightGoldenrodYellow,
            colframe=Gold!75!Goldenrod,
            boxrule=1pt,
            toptitle=1mm,
            bottomtitle=1mm,
            left=8pt,
            right=8pt,
            arc=0mm,
            opacityback=0.5,
            separator sign={.},
            breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{axiom}{\textbf{Axiom}}{%
                colback=LightGoldenrodYellow,
                colframe=Gold!75!Goldenrod,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{axiom}{\textbf{Axiôme}}{%
                    colback=LightGoldenrodYellow,
                    colframe=Gold!75!Goldenrod,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{axiom}{公理}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{axiom}{Axiom}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{axiom}{Axiôme}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Corollary
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{corollary}{\textbf{推论}}{%
            colback=Navy!30,
            colframe=NavyBlue!70!white,
            boxrule=1pt,
            toptitle=1mm,
            bottomtitle=1mm,
            left=8pt,
            right=8pt,
            arc=0mm,
            opacityback=0.5,
            separator sign={.},
            breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{corollary}{\textbf{Corollary}}{%
                colback=Navy!30,
                colframe=NavyBlue!70!white,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{corollary}{\textbf{Corollaire}}{%
                    colback=Navy!30,
                    colframe=NavyBlue!70!white,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{corollary}{推论}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{corollary}{Corollary}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{corollary}{Corollaire}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Remark
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{remark}{\textbf{注记}}{%
            colback=Salmon!20,
            colframe=Salmon!90!black,
            boxrule=1pt,
            toptitle=1mm,
            bottomtitle=1mm,
            left=8pt,
            right=8pt,
            arc=0mm,
            opacityback=0.5,
            separator sign={.},
            breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{remark}{\textbf{Remark}}{%
                colback=Salmon!20,
                colframe=Salmon!90!black,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{remark}{\textbf{Remarque}}{%
                    colback=Salmon!20,
                    colframe=Salmon!90!black,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{remark}{注记}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{remark}{Remark}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{remark}{Remarque}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Example
\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \newtcbtheorem[number within=section]{example}{\textbf{示例}}{%
            colback=ProcessBlue!20,
            colframe=RoyalBlue,
            boxrule=1pt,
            toptitle=1mm,
            bottomtitle=1mm,
            left=8pt,
            right=8pt,
            arc=0mm,
            opacityback=0.5,
            separator sign={.},
            breakable
        }{th}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \newtcbtheorem[number within=section]{example}{\textbf{Example}}{%
                colback=ProcessBlue!20,
                colframe=RoyalBlue,
                boxrule=1pt,
                toptitle=1mm,
                bottomtitle=1mm,
                left=8pt,
                right=8pt,
                arc=0mm,
                opacityback=0.5,
                separator sign={.},
                breakable
            }{th}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \newtcbtheorem[number within=section]{example}{\textbf{Exemple}}{%
                    colback=ProcessBlue!20,
                    colframe=RoyalBlue,
                    boxrule=1pt,
                    toptitle=1mm,
                    bottomtitle=1mm,
                    left=8pt,
                    right=8pt,
                    arc=0mm,
                    opacityback=0.5,
                    separator sign={.},
                    breakable
                }{th}
            }{
                \relax
            }
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \newtheorem{example}{示例}[section]
        }{
            \ifdefstring{\@cat@lang}{en}{
                \newtheorem{example}{Example}[section]
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \newtheorem{example}{Exemple}[section]
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Proof

\ifdefstring{\@cat@color}{default}{
    \ifdefstring{\@cat@lang}{zhcn}{
        \rcmd{\proofname}{证明}
    }{
        \ifdefstring{\@cat@lang}{en}{
            \rcmd{\proofname}{$\mathrm{Proof}$}
        }{
            \ifdefstring{\@cat@lang}{fr}{
                \rcmd{\proofname}{$\mathrm{Proof}$}
            }{
                \relax
            }
        }
    }
    \rcmd{\qedsymbol}{\color{Gold}{\DavidStarSolid}}
}{
    \ifdefstring{\@cat@color}{none}{
        \ifdefstring{\@cat@lang}{zhcn}{
            \rcmd{\proofname}{证明}
        }{
            \ifdefstring{\@cat@lang}{en}{
                \rcmd{\proofname}{$\mathrm{Proof}$}
            }{
                \ifdefstring{\@cat@lang}{fr}{
                    \rcmd{\proofname}{$\mathrm{Proof}$}
                }{
                    \relax
                }
            }
        }
    }{
        \relax
    }
}

%   Summary
\ifdefstring{\@cat@color}{default}{
    \tcbset{summary/.style={
        breakable,
        enhanced,
        colback=green!10,
        colframe=green!65!black,
        enlarge top by=5.5mm,
        overlay={\foreach \x in {2cm,3.5cm}{\begin{scope}
            [shift={([xshift=\x]frame.north west)}]
            \path[draw=green!65!black,fill=green!10,line width=1mm] (0,0) arc (0:180:5mm);
            \path[fill=black] (-0.2,0) arc (0:180:1mm);
        \end{scope}}},
        title=\textbf{内容提要}
        }
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \tcbset{summary/.style={
            breakable,
            enhanced,
            colback = white,
            colbacktitle = white,
            colframe = gray!50,
            coltitle = black,
            boxrule=0.2mm,
            attach boxed title to top left = {yshift=-\tcboxedtitleheight/2,  xshift=\tcboxedtitlewidth/4},
            boxed title style = {boxrule=0pt, colframe=white},
            before skip = 0.5cm,
            top = 3mm,
            bottom = 3mm,
            title=\textbf{内容提要}
            }
        }
    }{
        \relax
    }
}

%   List
\pack{enumitem}
\ifdefstring{\@cat@color}{default}{
    \definecolor{magicpurple}{HTML}{8767B6}
    \setlist[itemize,1]{label=\textcolor{magicpurple}{\small\DavidStar}}
    \setlist[itemize,2]{label=\textcolor{magicpurple}{\small\DavidStarSolid}}
    \setlist[itemize,3]{label=\textcolor{magicpurple}{\small\AsteriskCenterOpen}}
    \setlist[itemize,4]{label=\textcolor{magicpurple}{\small\AsteriskThinCenterOpen}}
}{
    \ifdefstring{\@cat@color}{none}{
        \setlist[itemize,1]{label={\small\DavidStar}}
        \setlist[itemize,2]{label={\small\DavidStarSolid}}
        \setlist[itemize,3]{label={\small\AsteriskCenterOpen}}
        \setlist[itemize,4]{label={\small\AsteriskThinCenterOpen}}
    }
}

%   New list environments
\ifdefstring{\@cat@color}{default}{
    \newenvironment{flowerlist}{ 
        \begin{list}{\textcolor{magicpurple}{\small\FiveFlowerPetal}}{}
    }{
        \end{list}
    }
    \newenvironment{openflowerlist}{
        \begin{list}{\textcolor{magicpurple}{\small\FiveFlowerOpen}}{}
    }{
        \end{list}
    }
    \newenvironment{scissorlist}{
        \begin{list}{\textcolor{magicpurple}{\small\ScissorHollowRight}}{}
    }{
        \end{list}
    }
    \newenvironment{arrowlist}{
        \begin{list}{\textcolor{magicpurple}{\small\ArrowBoldRightStrobe}}{}
    }{
        \end{list}
    }
}{
    \ifdefstring{\@cat@color}{none}{
        \newenvironment{flowerlist}{ 
            \begin{list}{\small\FiveFlowerPetal}{}
        }{
            \end{list}
        }
        \newenvironment{openflowerlist}{
            \begin{list}{\textcolor{magicpurple}{\small\FiveFlowerOpen}}{}
        }{
            \end{list}
        }
        \newenvironment{scissorlist}{
            \begin{list}{\small\ScissorHollowRight}{}
        }{
            \end{list}
        }
        \newenvironment{arrowlist}{
            \begin{list}{\small\ArrowBoldRightStrobe}{}
        }{
            \end{list}
        }
        }{
            \relax
        }
}




%!  Part III: Mode
%!  Math mode and text mode for your writing situation.

\ifdefstring{\@cat@mode}{math}{
    %   Complete omitted long arrow (\longtwoheadrightarrow for surjective map) for old-arrows 
    \DeclareRobustCommand\longtwoheadrightarrow{\relbar\joinrel\twoheadrightarrow}
    %   Distinguish the two \mathbb fonts provided by amsfonts and bbold
    \DeclareSymbolFontAlphabet{\mathbb}{AMSb}
    \DeclareSymbolFontAlphabet{\mathbbl}{bbold}
    %   Distinguish the two \mathscr fonts provided by mathrsfs and eucal
    \DeclareSymbolFontAlphabet{\mathscr}{rsfs}
    \cmd{\matheuscr}{\EuScript}
    %   elementary mathematics symbols
    \cmd{\e}{\operatorname{e}}                                                           %!  Natural logarithm
    \cmd{\dd}{\mathrm{d}}                                                                %!  Differental
    \cmd{\pt}{\operatorname{pt}}                                                         %!  Point set
    \cmd{\id}{\operatorname{id}}                                                         %!  Identity element
    \cmd{\identity}{\operatorname{id}}
    \cmd{\Id}{\operatorname{id}}
    \cmd{\Identity}{\operatorname{id}}
    \cmd{\op}{\operatorname{op}}                                                         %!  Opposite symbol
    \cmd{\opp}{\operatorname{op}}
    \cmd{\opposite}{\operatorname{op}}
    \rcmd{\gcd}{\operatorname{gcd}}                                                     %!  Greatest common divisor
    \cmd{\lcm}{\operatorname{lcm}}                                                       %!  Least common multiple
    \cmd{\codim}{\operatorname{codim}}                                                   %!  Codimension
    \cmd{\vol}{\operatorname{vol}}                                                       %!  Volumn
    \cmd{\Hol}{\operatorname{Hol}}                                                       %!  Holomorphism set
    %   linear algebra symbols
    \cmd{\End}{\operatorname{End}}                                                       %!  Endomorphism set
    \cmd{\Isom}{\operatorname{Isom}}                                                     %!  Isomorphism set
    \cmd{\Aut}{\operatorname{Aut}}                                                       %!  Automorphism set
    \cmd{\tr}{\operatorname{tr}}                                                         %!  Trace
    \cmd{\trace}{\operatorname{tr}}
    \cmd{\Tr}{\operatorname{tr}}
    \cmd{\Trace}{\operatorname{tr}}
    \cmd{\rk}{\operatorname{rk}}                                                         %!  Rank
    \cmd{\rank}{\operatorname{rk}}
    \cmd{\diag}{\operatorname{diag}}                                                     %!  Diagonal
    \rcmd{\span}{\operatorname{span}}                                                   %!  Span
    %   algebraic structure symbols
    \cmd{\Spec}{\operatorname{Spec}}                                                     %!  Prime (ideal) spectrum
    \cmd{\MaxSpec}{\operatorname{MaxSpec}}                                               %!  Maximum (ideal) spectrum
    \cmd{\rad}{\operatorname{rad}}                                                       %!  Radical
    \cmd{\Sym}{\operatorname{Sym}}                                                       %!  Symmetric algebra
    \cmd{\Gal}{\operatorname{Gal}}                                                       %!  Galois group
    \cmd{\Galois}{\operatorname{Gal}}
    \cmd{\Galgroup}{\operatorname{Gal}}
    \cmd{\Galoisgroup}{\operatorname{Gal}}
    \cmd{\gal}{\operatorname{Gal}}
    \cmd{\galois}{\operatorname{Gal}}
    \cmd{\galgroup}{\operatorname{Gal}}
    \cmd{\galoisgroup}{\operatorname{Gal}}
    \cmd{\GL}{\operatorname{GL}}                                                         %!  General linear group
    \cmd{\SL}{\operatorname{SL}}                                                         %!  Special linear group
    \cmd{\PGL}{\operatorname{PGL}}                                                       %!  Projective general linear group
    \cmd{\PSL}{\operatorname{PSL}}                                                       %!  Projective special linear group
    \rcmd{\O}{\operatorname{O}}                                                         %!  Orthogonal group
    \cmd{\SO}{\operatorname{SO}}                                                         %!  Special orthogonal group
    \cmd{\U}{\operatorname{U}}                                                           %!  Unitary group
    \cmd{\SU}{\operatorname{SU}}                                                         %!  Special unitary group
    \cmd{\Spin}{\operatorname{Spin}}                                                     %!  Lorentz group
    \cmd{\Lorentgroup}{\operatorname{Spin}}
    \cmd{\lorentzgroup}{\operatorname{Spin}}
    \cmd{\ghost}{\mathghost}                                                             %!  Ghost map (for Witt ring)
    \cmd{\bat}{\mathbat}                                                                 %!  Inverse ghost map (for Witt ring)
    %   category theory
    \cmd{\cat}{\mathcal}                                                                 %!  Category
    \cmd{\Ob}{\operatorname{Ob}}                                                         %!  Object
    \cmd{\Obj}{\operatorname{Ob}}
    \cmd{\Object}{\operatorname{Ob}}
    \cmd{\ob}{\operatorname{Ob}}
    \cmd{\obj}{\operatorname{Ob}}
    \cmd{\object}{\operatorname{Ob}}
    \cmd{\Mor}{\operatorname{Mor}}                                                       %!  Morphism
    \cmd{\Morphism}{\operatorname{Mor}}
    \cmd{\mor}{\operatorname{Mor}}
    \cmd{\morphism}{\operatorname{Mor}}
    \cmd{\Hom}{\operatorname{Hom}}                                                       %!  Hom set/functor
    \rcmd{\hom}{\operatorname{hom}}
    \cmd{\lHom}{\operatorname{\underline{\Hom}}}
    \cmd{\lhom}{\operatorname{\underline{\hom}}}
    \cmd{\iHom}{\operatorname{\mathscr{H}om}}                                            %!  Hom space
    \cmd{\RHom}{\operatorname{RHom}}                                                     %!  RHom
    \cmd{\Rhom}{\operatorname{Rhom}}
    \cmd{\lRHom}{\operatorname{R\underline{Hom}}}
    \cmd{\lRhom}{\operatorname{R\underline{hom}}}
    \cmd{\Map}{\operatorname{Map}}                                                       %!  Mapping space
    \cmd{\Fun}{\operatorname{Fun}}                                                       %!  Functor category
    \cmd{\Functor}{\operatorname{Fun}}
    \cmd{\fun}{\operatorname{Fun}}
    \cmd{\functor}{\operatorname{Fun}}
    \cmd{\Fct}{\operatorname{Fun}}
    \cmd{\fct}{\operatorname{Fun}}
    \rcmd{\ker}{\operatorname{ker}}                                                     %!  Kernal/equalizer
    \cmd{\kernal}{\operatorname{ker}}
    \cmd{\coker}{\operatorname{coker}}                                                   %!  Cokernal/equalizer
    \cmd{\cokernal}{\operatorname{coker}}
    \cmd{\im}{\operatorname{im}}                                                         %!  Image
    \cmd{\image}{\operatorname{im}}
    \cmd{\coim}{\operatorname{coim}}                                                     %!  Coimage
    \cmd{\coimage}{\operatorname{coim}}
    \cmd{\pr}{\operatorname{pr}}                                                         %!  Projection
    \cmd{\Rvarprojlim}{\mathrm{R}\varprojlim}                                            %!  Rlim projective version
    \cmd{\Rvarinjlim}{\mathrm{R}\varinjlim}                                              %!  Rlim injective version
    \cmd{\hoprojlim}{\mathop{\operatorname{holim}}\limits_{\longleftarrow}}              %!  Homotopy projective limit
    \cmd{\hoinjlim}{\mathop{\operatorname{holim}} \limits_{\longrightarrow}}             %!  Homotopy injective limit
    \cmd{\Ext}{\operatorname{Ext}}                                                       %!  Ext functor
    \cmd{\Tor}{\operatorname{Tor}}                                                       %!  Tor functor
    \cmd{\D}{\operatorname{\mathsf{D}}}                                                  %!  Derived category
    \cmd{\LD}{\operatorname{\mathsf{L}}}                                                 %!  Left derived functor
    \cmd{\RD}{\operatorname{\mathsf{R}}}                                                 %!  Right derived functor
    \cmd{\Lan}{\operatorname{Lan}}                                                       %!  Left Kan extension
    \cmd{\Ran}{\operatorname{Ran}}                                                       %!  Right Kan extension
    \cmd{\Cone}{\operatorname{Cone}}                                                     %!  Mapping cone
    \cmd{\Cyl}{\operatorname{Cyl}}                                                       %!  Mapping cylinder
    \cmd{\ind}{\mathrm{ind}}                                                             %!  Ind-object
    \cmd{\pro}{\mathrm{pro}}                                                             %!  Pro-object
    \cmd{\projdim}{\operatorname{proj.dim}}                                              %!  Projective dimension
    \cmd{\injdim}{\operatorname{inj.dim}}                                                %!  Injective dimension
    %   higher category, topos, algebra and model category
    \cmd{\Ho}{\operatorname{\mathsf{Ho}}}                                                %!  Homotopy category
    \cmd{\Homotopy}{\operatorname{\mathsf{Ho}}}
    \cmd{\Homotopycat}{\operatorname{\mathsf{Ho}}}
    \cmd{\Homotopycategory}{\operatorname{\mathsf{Ho}}}
    \cmd{\ho}{\operatorname{\mathsf{Ho}}}
    \cmd{\homotopy}{\operatorname{\mathsf{Ho}}}
    \cmd{\homotopycat}{\operatorname{\mathsf{Ho}}}
    \cmd{\homotopycategory}{\operatorname{\mathsf{Ho}}}
    \cmd{\weq}{\operatorname{weq}}                                                       %!  Weak equivalence collection
    \cmd{\weakequiv}{\operatorname{weq}}
    \cmd{\weakequivalence}{\operatorname{weq}}
    \cmd{\fib}{\operatorname{fib}}                                                       %!  Fibrant collection
    \cmd{\fibrant}{\operatorname{fib}}
    \cmd{\Fib}{\operatorname{fib}}
    \cmd{\Fibrant}{\operatorname{fib}}
    \cmd{\cofib}{\operatorname{cofib}}                                                   %!  Cofibrant collection
    \cmd{\cofibrant}{\operatorname{cofib}}
    \cmd{\Cofib}{\operatorname{cofib}}
    \cmd{\Cofibrant}{\operatorname{cofib}}
    \cmd{\CoFib}{\operatorname{cofib}}
    \cmd{\CoFibrant}{\operatorname{cofib}}
    \cmd{\coFib}{\operatorname{cofib}}
    \cmd{\coFibrant}{\operatorname{cofib}}
    \cmd{\Path}{\operatorname{Path}}                                                     %!  Path object
    \cmd{\N}{\operatorname{N}}                                                           %!  Nerve
    \cmd{\nerve}{\operatorname{N}}
    \cmd{\Nerve}{\operatorname{Nerve}}
    \cmd{\Spi}{\operatorname{Spi}}                                                       %!  Spine
    \cmd{\Spine}{\operatorname{Spi}}
    \cmd{\spi}{\operatorname{Spi}}
    \cmd{\spine}{\operatorname{Spi}}
    %   homology algebra and algebraic topology
    \cmd{\gr}{\operatorname{gr}}                                                         %!  Graded object
    \cmd{\tot}{\operatorname{tot}}                                                       %!  Total complex
    \cmd{\Kos}{\operatorname{Kos}}                                                       %!  Koszul complex
    \cmd{\CE}{\operatorname{CE}}                                                         %!  Chevalley-Eilenberg complex
    %   algebraic geometry and homotopy algebraic geometry
    \cmd{\Cov}{\operatorname{Cov}}                                                       %!  Coverage/general covering collection
    \rcmd{\div}{\operatorname{div}}                                                     %!  Divisor
    \cmd{\Spf}{\operatorname{Spf}}                                                       %!  Formal spectrum
    \cmd{\dotimes}{\overset{\mathbb{L}}{\otimes}}                                        %!  Derived tensor product
    %   arithmetic geometry
    \cmd{\KS}{\operatorname{KS}}                                                         %!  Kodaira-Spencer isomorphism
    \cmd{\ES}{\operatorname{ES}}                                                         %!  Eichler-Shimura isomorphism
    \cmd{\Tate}{\operatorname{Tate}}                                                     %!  Tate curve
    \cmd{\Spa}{\operatorname{Spa}}                                                       %!  Adic space           
    \cmd{\Spd}{\operatorname{Spd}}
    \cmd{\Fil}{\operatorname{Fil}}                                                       %!  Filter
    \cmd{\prism}{{\mathlarger{\mathbbl{\Delta}}}}                                        %!  Prism
    \cmd{\Prism}{{\mathlarger{\mathbbl{\Delta}}}}
    %   Langlands correspondence
    \cmd{\Sht}{\operatorname{Sht}}                                                       %!  Moduli space of Shtuka ($F$-sheaf)
    \cmd{\Shtuka}{\operatorname{Sht}}
    \cmd{\sht}{\operatorname{Sht}}
    \cmd{\shtuka}{\operatorname{Sht}}
    \cmd{\Hecke}{\operatorname{Hecke}}                                                   %!  Hecke stack
    %   Mathematical physics
    \cmd{\Crit}{\operatorname{Crit}}                                                     %!  Critical subspace/locus
    \cmd{\dCrit}{\operatorname{dCrit}}                                                   %!  Derived critical subspace/locus
}{
    \ifdefstring{\@cat@mode}{text}{
        %   Complete omitted long arrow (\longtwoheadrightarrow for surjective map) for old-arrows 
        \DeclareRobustCommand\longtwoheadrightarrow{\relbar\joinrel\twoheadrightarrow}
        %   Distinguish the two \mathbb fonts provided by amsfonts and bbold
        \DeclareSymbolFontAlphabet{\mathbb}{AMSb}
        \DeclareSymbolFontAlphabet{\mathbbl}{bbold}
        %   Distinguish the two \mathscr fonts provided by mathrsfs and eucal
        \DeclareSymbolFontAlphabet{\mathscr}{rsfs}
        \cmd{\matheuscr}{\EuScript}
    }{
        \relax
    }
}




%!  Part IV: Expansion of arrows
%!  Some new retractable arrows by tikz.

\makeatletter
\newbox\xratbelow
\newbox\xratabove
\rcmd{\xrightarrow}[2][]{%
	\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
	\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
	\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
	\mathrel{\tikz [->, baseline=-.75ex]
		\draw (0,0) -- node[below=-2pt] {\box\xratbelow}
		node[above] {\box\xratabove}
		(\xratlen,0) ;}}
\rcmd{\xleftarrow}[2][]{%
	\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
	\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
	\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
	\mathrel{\tikz [<-, baseline=-.75ex]
		\draw (0,0) -- node[below] {\box\xratbelow}
		node[above] {\box\xratabove}
		(\xratlen,0) ;}}
\rcmd{\xleftrightarrow}[2][]{%
	\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
	\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
	\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
	\mathrel{\tikz [<->, baseline=-.75ex]
		\draw (0,0) -- node[below] {\box\xratbelow}
		node[above] {\box\xratabove}
		(\xratlen,0) ;}}
\rcmd{\xhookrightarrow}[2][]{%
	\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
	\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
	\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
	\mathrel{\tikz [baseline=-.75ex]
		\draw (0,0) edge[commutative diagrams/hookrightarrow] node[below] {\box\xratbelow}
		node[above] {\box\xratabove}
		(\xratlen,0) ;}}
\rcmd{\xhookleftarrow}[2][]{%
	\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
	\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
	\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
	\mathrel{\tikz [baseline=-.75ex]
		\draw (0,0) edge[commutative diagrams/hookleftarrow] node[below] {\box\xratbelow}
		node[above] {\box\xratabove}
		(\xratlen,0) ;}}
\rcmd{\xmapsto}[2][]{%
	\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
	\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
	\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
	\mathrel{\tikz [baseline=-.75ex]
		\draw (0,0) edge[commutative diagrams/mapsto] node[below] {\box\xratbelow}
		node[above] {\box\xratabove}
		(\xratlen,0) ;}}
\cmd{\xlongequal}[2][]{%
	\setbox\xratbelow=\hbox{\ensuremath{\scriptstyle #1}}%
	\setbox\xratabove=\hbox{\ensuremath{\scriptstyle #2}}%
	\pgfmathsetlengthmacro{\xratlen}{max(\wd\xratbelow, \wd\xratabove) + .6em}%
	\mathrel{\tikz [baseline=-.75ex]
		\draw (0,0) edge[commutative diagrams/equal] node[below] {\box\xratbelow}
		node[above] {\box\xratabove}
		(\xratlen,0) ;}}
\makeatother
\endinput